package com.sample.generator.demo;

import java.io.File;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class Sample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Configuration configuration = new Configuration();
		File templatesDir = new File("./templates");

		// throws IOException
		try {
			configuration.setDirectoryForTemplateLoading(templatesDir);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Template template = null;
		try {
			template = configuration.getTemplate("test.ftl");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Map<String, Object> root = new HashMap<String, Object>();

		root.put("string", "string");
		root.put("int", new Integer(100));

		Writer out = new OutputStreamWriter(System.out);
		try {
			template.process(root, out);
			out.flush();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TemplateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
